<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
		<title></title>

		<link rel="stylesheet" href="http://127.0.0.1/hdwy/wasai/Public/Bootstrap/Css/bootstrap.min.css" />
		<link rel="stylesheet" href="http://127.0.0.1/hdwy/wasai/Application/Admin/View/Public/Css/common.css" />
		<!--载入uoloadify上传插件相关文件-->
		<script type="text/javascript" src="http://127.0.0.1/hdwy/wasai/Static/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="http://127.0.0.1/hdwy/wasai/Static/uploadify/jquery.uploadify.min.js"></script>
		<link href="http://127.0.0.1/hdwy/wasai/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
		<link rel="stylesheet" type="text/css" href="http://127.0.0.1/hdwy/wasai/Static/hdjs/hdjs.css" />

		<!--载入百度编辑器相关文件-->
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/hdwy/wasai/Static/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/hdwy/wasai/Static/ueditor1_4_3/ueditor.all.min.js">
		</script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/hdwy/wasai/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
		<!--删除图片-->
		<script type="text/javascript">
			//点击x删除图片
			$('.del-img').live('click',function(){
				var liObj = $(this).parents('li');
				//找到父级li里面的地址
				var path = liObj.attr('path');
				//发异步到服务器删除
				$.ajax({
					type:"post",
					url:"<?php echo U('delImg');?>",
					data:{path:path},
					success:function(data){
						//移除图片
						liObj.remove();
					}
				});
			})
		</script>
		<!--异步调取规格和属性-->
		<script type="text/javascript" charset="utf-8">
			$(function(){
			      $('select[name=category_cid]').change(function(){
					//判断当选择顶级分类后弹窗提示不能选择顶级分类
					//获得选中的option的类型pid
					var pid = $(':selected').attr('pid');
					if(pid==0){
						alert('添加商品不能选择顶级分类');
					}      	
			        //获得选中的option的类型gid
			        var tid = $(':selected').attr('tid');
			      	//发送异步
			        $.ajax({
			          type:"post",
			          url:"<?php echo U('getAttrSpec');?>",
			          data:{tid : tid},
			          dataType:'json',
			          success:function(phpData){
			            //属性
			            var attr = '';
			            //规格
			            var spec = '';
			            $.each(phpData, function(k,v) {    
			              //如果是属性(不可选)  
			              if(v.attr_type == 0){
							  	attr += '<tr><td>'+v.ta_name+'</td><td><select name="attr['+v.ta_id+']"><option value="0">请选择</option>';
							  	$.each(v.ta_value, function(kk,vv) {    
							  		attr += '<option value="'+vv+'">' + vv + '</option>';                                                          
							  	});
							  	attr += '</select></td></tr>';
			              }else{
			              	//如果是规格(可选)
			                spec += '<tr><td>'+v.ta_name+'</td><td><select name="spec['+v.ta_id+'][spec_val][]"><option>请选择</option>';
			                  $.each(v.ta_value, function(kk,vv) {    
			                    spec += '<option>' + vv + '</option>';                                                          
			                  });
			                  spec += '</select></td><td>附加价格 <input type="" name="spec['+v.ta_id+'][added][]" id="" value="0.00" /></td><td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>添加规格</span></td></tr>';
			              }
			            });
			            
			            $('#attr').html(attr);
			            $('#spec').html(spec);
			            
			          }
			        });
			      })
			    })
		</script>
		<!--异步调取规格和属性结束-->

		<!--增加和删除一项规格-->
		<script type="text/javascript">
			$('.add-spec').live('click', function () {
			    var tr = $(this).parents('tr');
			    var obj = tr.clone();
			    var del = '<span class="del-spec btn btn-info"><i class="icon-white icon-minus"></i>删除规格</span>';
			    obj.find('td').eq(3).find('.add-spec').remove();
			    obj.find('td').eq(3).append(del);
			    tr.after(obj);
			  });
			
			  //删除一个规格
			  $('.del-spec').live('click', function() {
			    $(this).parents('tr').remove();
			  });
		</script>
		<!--增加和删除一项规格结束-->
	</head>

	<body>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">

					<form action="" method='post' enctype="multipart/form-data">
						<fieldset>
							<legend>发布商品</legend>
							<table class='table table-bordered table-hover'>
								<thead>
									<tr>
										<th colspan="2" class="btn btn-primary">基本信息</th>
									</tr>
								</thead>
								<tbody>
									<tr class="info">
										<td>所属分类</td>
										<td>
											<select name="category_cid">
												<option value="0">请选择</option>
												<?php foreach ($cateData as $k=>$v){?>
													<option value="<?php echo $v['cid'];?>" tid="<?php echo $v['type_tid'];?>" pid="<?php echo $v['pid'];?>"><?php echo $v['_name'];?></option>
												<?php }?>
											</select>
										</td>
									</tr>
									<tr class="info">
										<td>所属品牌</td>
										<td>
											<select name="brand_bid">
												<option value="0">请选择</option>
												<?php foreach ($brandData as $k=>$v){?>
													<option value="<?php echo $v['bid'];?>"><?php echo $v['bname'];?></option>
												<?php }?>
											</select>
										</td>
									</tr>
									<tr class="info">
										<td>商品名称</td>
										<td>
											<input type="text" name='sname' />
										</td>
									</tr>
									<tr class="info">
										<td>单位</td>
										<td>
											<input type="text" name='unit' value='件' />
										</td>
									</tr>
									<tr class="info">
										<td>市价场</td>
										<td>
											<input type="text" name='marketprice' value="0.00" />
										</td>
									</tr>
									<tr class="info">
										<td>商城价</td>
										<td>
											<input type="text" name='shopprice' value="0.00"/>
										</td>
									</tr>
								</tbody>
							</table>

							<p class="btn btn-primary">商品属性</p>
							<table class="table table-bordered table-hover" id='attr' class="info">

							</table>
							<p class="btn btn-primary">商品规格</p>
							<table class="table table-bordered table-hover" id='spec'>

							</table>

							<table class='table table-bordered'>
								<tr>
									<th colspan="3" class="btn btn-primary">列表图</th>
								</tr>
								<tr class="info">
									<td>上传图片</td>
									<td>
										<div lab="uploadFile">
											<input id="file" type="file" multiple="true">
											<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
											<script type="text/javascript">
												$(function() {
								                    $('#file').uploadify({
								                        'formData'     : {//POST数据
								                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
								                        },
								                        'fileTypeDesc' : '上传文件',//上传描述
								                        'fileTypeExts' : '*.jpg;*.png;*.jpeg',
								                        'swf'      : 'http://127.0.0.1/hdwy/wasai/Static/uploadify/uploadify.swf',
								                        'uploader' : '<?php echo U("upload_list");?>',
								                        'buttonText':'选择文件',
								                        'fileSizeLimit' : '2000KB',
								                        'uploadLimit' : 1000,//上传文件数
								                        'width':65,
								                        'height':25,
								                        'successTimeout':10,//等待服务器响应时间
								                        'removeTimeout' : 0.2,//成功显示时间
								                        'onUploadSuccess' : function(file, data, response) {
								                            data=$.parseJSON(data);
								                            var imageUrl = data.image?data.url:'http://127.0.0.1/hdwy/wasai/Static/image/default.png';
								                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:200px;heigth:200px;'/><a href='javascript:;' style='color:#fff' class='del-img btn btn-info'>删除</a>";
								                            //把地址放到隐藏域，这样可以提交到服务器了
								                            li += '<input type="hidden" name="pic" value="'+data.path+'"/>';
								                            li += '</li>';
								                            $("#picList ul").prepend(li);
								                        }
								                    });
										         });
											</script>
										</div>
									</td>
									<td id='picList'>
										<ul>

										</ul>
									</td>
								</tr>
							</table>

							<table class='table table-bordered'>
								<tr>
									<th colspan="3" class="btn btn-primary">商品图册</th>
								</tr>
								<tr class="info">
									<td>上传图片</td>
									<td>
										<div lab="uploadFile">
											<input id="photo" type="file" multiple="true">
											<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
								            <script type="text/javascript">
								                $(function() {
								                    $('#photo').uploadify({
								                        'formData'     : {//POST数据
								                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
								                        },
								                        'fileTypeDesc' : '上传文件',//上传描述
								                        'fileTypeExts' : '*.jpg;*.png;*.jpeg',
								                        'swf'      : 'http://127.0.0.1/hdwy/wasai/Static/uploadify/uploadify.swf',
								                        'uploader' : '<?php echo U("upload_shop");?>',
								                        'buttonText':'选择文件',
								                        'fileSizeLimit' : '2000KB',
								                        'uploadLimit' : 1000,//上传文件数
								                        'width':65,
								                        'height':25,
								                        'successTimeout':10,//等待服务器响应时间
								                        'removeTimeout' : 0.2,//成功显示时间
								                        'onUploadSuccess' : function(file, data, response) {
								                            data=$.parseJSON(data);
								                            var li = '';
								                            $.each(data, function(k,v) {  
								                            	    li += "<li path='"+v+"' ><img src='http://127.0.0.1/hdwy/wasai/"+v+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:#fff' class='del-pic btn btn-info'>删除</a>";
								                                	li += '<input type="hidden" name="thumb[]" id="thumb" value="'+v+'" />';  0                  
								                            });
								                            $("#photoList ul").prepend(li);
								                        }
								                    });
								                });
						           			 </script>
										</div>
									</td>
									<td id='photoList'>
										<ul>

										</ul>
									</td>
								</tr>
							</table>
				           <script type="text/javascript">
								//点击删除商品图册图片
								$('.del-pic').live('click',function(){
									var liObj = $(this).parents('li');
									//到父级li里面的地址
									var path = liObj.attr('path');
									//发异步到服务器删除
									$.ajax({
										type:"post",
										url:"<?php echo U('delImg');?>",
										data:{path:path},
										success:function(data){
											//移除图片
											liObj.remove();
										}
									});
								})
							</script>
							<table class='table'>
								<tr class="next_show">
									<th class="btn btn-primary">商品详细</th>
								</tr>
								<td>
									<script id="editor" type="text/plain" style="width:1080px;height:500px;" name="intro"></script>
									<script>
										var ue = UE.getEditor('editor');
									</script>
								</td>
								<tr class="hide info">
									<td>
										<textarea name="intro" id="intro"></textarea>
									</td>
								</tr>
							</table>
							<input type="hidden" name='tid' value='0'/>
							<input type="submit" value="确认发布" class="btn btn-primary btn-block btn-large" />
						</fieldset>
					</form>

				</div>
			</div>
		</div>
	</body>

</html>